package org.lex.jdbc.url.view.internal;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;

import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.lex.swing.Swings;

public class DriverConfigPane extends JPanel {

	public static void main(String[] args) {
		Swings.tryToUseSystemLookAndFeel();
		Swings.show(new DriverConfigPane());
	}

	private static final long serialVersionUID = 3095434178826089109L;
	private JTabbedPane tabbedPane;
	private JPanel driverPane;
	private JPanel templatePane;
	private JPanel metaDataPane;
	private JLabel driverNameLabel;
	private JComboBox driverNameComboBox;
	private JLabel websiteLabel;
	private JTextField websiteTextField;
	private JLabel driverDescriptionLabel;
	private JTextField driverDescriptionTextField;
	private JPanel classpathPane;
	private JScrollPane classpathScrollPane;
	private JList<File> classpathList;
	private DefaultListModel<File> classpathListModel;
	private JPanel classpathControlPane;
	private JButton addFileButton;
	private JButton editButton;
	private JButton removeButton;
	private JButton listDriversButton;
	private JLabel classLabel;
	private JComboBox<String> classComboBox;
	private DefaultComboBoxModel<String> classComboBoxModel;
	private JPanel templateMetaDataPane;
	private JPanel variablePane;
	private JLabel templateNameLabel;
	private JComboBox templateNameComboBox;
	private JLabel templateLabel;
	private JTextField templateTextField;
	private JLabel templateDriverLabel;
	private JComboBox templateDriverComboBox;
	private JScrollPane variableScrollPane;
	private JPanel variableControlPane;
	private JButton addVariableButton;
	private JButton removeVariableButton;
	private Component verticalGlue;
	private Component verticalGlue_1;
	private JTable variableTable;
	private JLabel templateDescriptionLabel;
	private JTextField templateDescriptionTextField;

	private DriverConfigPaneOper oper;

	/**
	 * Create the panel.
	 */
	public DriverConfigPane() {
		initialize();
	}

	void addDriverFile(File file) {
		this.getClasspathListModel().addElement(file);
	}

	DefaultListModel<File> getClasspathListModel() {
		if (null == this.classpathListModel) {
			this.classpathListModel = new DefaultListModel<File>();
		}
		return this.classpathListModel;
	}

	DefaultComboBoxModel<String> getClassComboBoxModel() {
		if (null == this.classComboBoxModel) {
			this.classComboBoxModel = new DefaultComboBoxModel<String>();
		}
		return this.classComboBoxModel;
	}

	private DriverConfigPaneOper getOper() {
		if (null == this.oper) {
			this.oper = new DriverConfigPaneOper(this);
		}
		return this.oper;
	}

	private void initialize() {
		this.setPreferredSize(new Dimension(500, 400));
		setLayout(new BorderLayout(0, 0));
		add(getTabbedPane(), BorderLayout.CENTER);
	}

	private JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane(JTabbedPane.TOP);
			tabbedPane.addTab("Driver", null, getDriverPane(), null);
			tabbedPane.addTab("Template", null, getTemplatePane(), null);
		}
		return tabbedPane;
	}

	private JPanel getDriverPane() {
		if (driverPane == null) {
			driverPane = new JPanel();
			GridBagLayout driverPaneGridBagLayout = new GridBagLayout();
			driverPane.setLayout(driverPaneGridBagLayout);
			GridBagConstraints metaDataPaneGridBagConstraints = new GridBagConstraints();
			metaDataPaneGridBagConstraints.gridwidth = 2;
			metaDataPaneGridBagConstraints.weightx = 10.0;
			metaDataPaneGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			metaDataPaneGridBagConstraints.gridx = 0;
			metaDataPaneGridBagConstraints.gridy = 0;
			driverPane.add(getMetaDataPane(), metaDataPaneGridBagConstraints);
			GridBagConstraints classpathPaneGridBagConstraints = new GridBagConstraints();
			classpathPaneGridBagConstraints.weighty = 10.0;
			classpathPaneGridBagConstraints.weightx = 10.0;
			classpathPaneGridBagConstraints.gridwidth = 2;
			classpathPaneGridBagConstraints.fill = GridBagConstraints.BOTH;
			classpathPaneGridBagConstraints.gridx = 0;
			classpathPaneGridBagConstraints.gridy = 1;
			driverPane.add(getClasspathPane(), classpathPaneGridBagConstraints);
		}
		return driverPane;
	}

	private JPanel getTemplatePane() {
		if (templatePane == null) {
			templatePane = new JPanel();
			GridBagLayout templatePaneGridBagLayout = new GridBagLayout();
			templatePane.setLayout(templatePaneGridBagLayout);
			GridBagConstraints templateMetaDataPaneGridBagConstraints = new GridBagConstraints();
			templateMetaDataPaneGridBagConstraints.weightx = 10.0;
			templateMetaDataPaneGridBagConstraints.anchor = GridBagConstraints.PAGE_START;
			templateMetaDataPaneGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			templateMetaDataPaneGridBagConstraints.gridx = 0;
			templateMetaDataPaneGridBagConstraints.gridy = 0;
			templatePane.add(getTemplateMetaDataPane(),
					templateMetaDataPaneGridBagConstraints);
			GridBagConstraints variablePaneGridBagConstraints = new GridBagConstraints();
			variablePaneGridBagConstraints.anchor = GridBagConstraints.PAGE_START;
			variablePaneGridBagConstraints.weighty = 10.0;
			variablePaneGridBagConstraints.weightx = 10.0;
			variablePaneGridBagConstraints.fill = GridBagConstraints.BOTH;
			variablePaneGridBagConstraints.gridx = 0;
			variablePaneGridBagConstraints.gridy = 1;
			templatePane.add(getVariablePane(), variablePaneGridBagConstraints);
		}
		return templatePane;
	}

	private JPanel getMetaDataPane() {
		if (metaDataPane == null) {
			metaDataPane = new JPanel();
			metaDataPane.setBorder(new TitledBorder(null, "Driver",
					TitledBorder.LEADING, TitledBorder.TOP, null, null));
			GridBagLayout metaDataPaneGridBagLayout = new GridBagLayout();
			metaDataPane.setLayout(metaDataPaneGridBagLayout);
			GridBagConstraints driverNameLabelGridBagConstraints = new GridBagConstraints();
			driverNameLabelGridBagConstraints.insets = new Insets(0, 0, 5, 5);
			driverNameLabelGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			driverNameLabelGridBagConstraints.gridx = 0;
			driverNameLabelGridBagConstraints.gridy = 0;
			metaDataPane.add(getDriverNameLabel(),
					driverNameLabelGridBagConstraints);
			GridBagConstraints driverNameComboBoxGridBagConstraints = new GridBagConstraints();
			driverNameComboBoxGridBagConstraints.weightx = 10.0;
			driverNameComboBoxGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			driverNameComboBoxGridBagConstraints.insets = new Insets(0, 0, 5, 0);
			driverNameComboBoxGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			driverNameComboBoxGridBagConstraints.gridx = 1;
			driverNameComboBoxGridBagConstraints.gridy = 0;
			metaDataPane.add(getDriverNameComboBox(),
					driverNameComboBoxGridBagConstraints);
			GridBagConstraints websiteLabelGridBagConstraints = new GridBagConstraints();
			websiteLabelGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			websiteLabelGridBagConstraints.insets = new Insets(0, 0, 5, 5);
			websiteLabelGridBagConstraints.gridx = 0;
			websiteLabelGridBagConstraints.gridy = 1;
			metaDataPane.add(getWebsiteLabel(), websiteLabelGridBagConstraints);
			GridBagConstraints websiteTextFieldGridBagConstraints = new GridBagConstraints();
			websiteTextFieldGridBagConstraints.weightx = 10.0;
			websiteTextFieldGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			websiteTextFieldGridBagConstraints.insets = new Insets(0, 0, 5, 0);
			websiteTextFieldGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			websiteTextFieldGridBagConstraints.gridx = 1;
			websiteTextFieldGridBagConstraints.gridy = 1;
			metaDataPane.add(getWebsiteTextField(),
					websiteTextFieldGridBagConstraints);
			GridBagConstraints driverDescriptionLabelGridBagConstraints = new GridBagConstraints();
			driverDescriptionLabelGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			driverDescriptionLabelGridBagConstraints.insets = new Insets(0, 0,
					5, 5);
			driverDescriptionLabelGridBagConstraints.gridx = 0;
			driverDescriptionLabelGridBagConstraints.gridy = 2;
			metaDataPane.add(getDriverDescriptionLabel(),
					driverDescriptionLabelGridBagConstraints);
			GridBagConstraints driverDescriptionTextFieldGridBagConstraints = new GridBagConstraints();
			driverDescriptionTextFieldGridBagConstraints.weightx = 10.0;
			driverDescriptionTextFieldGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			driverDescriptionTextFieldGridBagConstraints.insets = new Insets(0,
					0, 5, 0);
			driverDescriptionTextFieldGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			driverDescriptionTextFieldGridBagConstraints.gridx = 1;
			driverDescriptionTextFieldGridBagConstraints.gridy = 2;
			metaDataPane.add(getDriverDescriptionTextField(),
					driverDescriptionTextFieldGridBagConstraints);
		}
		return metaDataPane;
	}

	private JLabel getDriverNameLabel() {
		if (driverNameLabel == null) {
			driverNameLabel = new JLabel("Name");
		}
		return driverNameLabel;
	}

	private JComboBox getDriverNameComboBox() {
		if (driverNameComboBox == null) {
			driverNameComboBox = new JComboBox();
		}
		return driverNameComboBox;
	}

	private JLabel getWebsiteLabel() {
		if (websiteLabel == null) {
			websiteLabel = new JLabel("Website");
		}
		return websiteLabel;
	}

	private JTextField getWebsiteTextField() {
		if (websiteTextField == null) {
			websiteTextField = new JTextField();
			websiteTextField.setColumns(10);
		}
		return websiteTextField;
	}

	private JLabel getDriverDescriptionLabel() {
		if (driverDescriptionLabel == null) {
			driverDescriptionLabel = new JLabel("Description");
		}
		return driverDescriptionLabel;
	}

	private JTextField getDriverDescriptionTextField() {
		if (driverDescriptionTextField == null) {
			driverDescriptionTextField = new JTextField();
			driverDescriptionTextField.setColumns(10);
		}
		return driverDescriptionTextField;
	}

	private JPanel getClasspathPane() {
		if (classpathPane == null) {
			classpathPane = new JPanel();
			classpathPane.setBorder(new TitledBorder(null, "Classpath",
					TitledBorder.LEADING, TitledBorder.TOP, null, null));
			GridBagLayout classpathPaneGridBagLayout = new GridBagLayout();
			classpathPaneGridBagLayout.columnWeights = new double[] { 0.0, 1.0,
					0.0 };
			classpathPane.setLayout(classpathPaneGridBagLayout);
			GridBagConstraints classpathScrollPaneGridBagConstraints = new GridBagConstraints();
			classpathScrollPaneGridBagConstraints.gridwidth = 2;
			classpathScrollPaneGridBagConstraints.insets = new Insets(0, 0, 5,
					5);
			classpathScrollPaneGridBagConstraints.weighty = 10.0;
			classpathScrollPaneGridBagConstraints.weightx = 10.0;
			classpathScrollPaneGridBagConstraints.fill = GridBagConstraints.BOTH;
			classpathScrollPaneGridBagConstraints.gridx = 0;
			classpathScrollPaneGridBagConstraints.gridy = 0;
			classpathPane.add(getClasspathScrollPane(),
					classpathScrollPaneGridBagConstraints);
			GridBagConstraints classpathControlPaneGridBagConstraints = new GridBagConstraints();
			classpathControlPaneGridBagConstraints.insets = new Insets(0, 0, 5,
					0);
			classpathControlPaneGridBagConstraints.anchor = GridBagConstraints.PAGE_START;
			classpathControlPaneGridBagConstraints.weighty = 10.0;
			classpathControlPaneGridBagConstraints.fill = GridBagConstraints.VERTICAL;
			classpathControlPaneGridBagConstraints.gridx = 2;
			classpathControlPaneGridBagConstraints.gridy = 0;
			classpathPane.add(getClasspathControlPane(),
					classpathControlPaneGridBagConstraints);
			GridBagConstraints classLabelGridBagConstraints = new GridBagConstraints();
			classLabelGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			classLabelGridBagConstraints.insets = new Insets(0, 0, 0, 5);
			classLabelGridBagConstraints.gridx = 0;
			classLabelGridBagConstraints.gridy = 1;
			classpathPane.add(getClassLabel(), classLabelGridBagConstraints);
			GridBagConstraints classComboBoxGridBagConstraints = new GridBagConstraints();
			classComboBoxGridBagConstraints.weightx = 10.0;
			classComboBoxGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			classComboBoxGridBagConstraints.gridwidth = 2;
			classComboBoxGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			classComboBoxGridBagConstraints.gridx = 1;
			classComboBoxGridBagConstraints.gridy = 1;
			classpathPane.add(getClassComboBox(),
					classComboBoxGridBagConstraints);
		}
		return classpathPane;
	}

	private JScrollPane getClasspathScrollPane() {
		if (classpathScrollPane == null) {
			classpathScrollPane = new JScrollPane();
			classpathScrollPane.setViewportView(getClasspathList());
		}
		return classpathScrollPane;
	}

	JList<File> getClasspathList() {
		if (classpathList == null) {
			classpathList = new JList<File>(this.getClasspathListModel());
			classpathList
					.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
			classpathList.addListSelectionListener(new ListSelectionListener() {
				@Override
				public void valueChanged(ListSelectionEvent e) {
					int[] selected = classpathList.getSelectedIndices();
					switch (selected.length) {
					case 0:
						getEditButton().setEnabled(false);
						getRemoveButton().setEnabled(false);
						break;
					case 1:
						getEditButton().setEnabled(true);
						getRemoveButton().setEnabled(true);
						break;
					default:
						getEditButton().setEnabled(false);
						getRemoveButton().setEnabled(true);
						break;
					}
				}
			});
			classpathList.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					if (e.getClickCount() > 1
							&& classpathList.getModel().getSize() > 0) {
						getOper().editDriverFileAction(e);
					}
				}
			});
		}
		return classpathList;
	}

	private JPanel getClasspathControlPane() {
		if (classpathControlPane == null) {
			classpathControlPane = new JPanel();
			GridBagLayout classpathControlPaneGridBagLayout = new GridBagLayout();
			classpathControlPane.setLayout(classpathControlPaneGridBagLayout);
			GridBagConstraints addFileButtonGridBagConstraints = new GridBagConstraints();
			addFileButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			addFileButtonGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			addFileButtonGridBagConstraints.insets = new Insets(0, 0, 5, 0);
			addFileButtonGridBagConstraints.gridx = 0;
			addFileButtonGridBagConstraints.gridy = 0;
			classpathControlPane.add(getAddFileButton(),
					addFileButtonGridBagConstraints);
			GridBagConstraints editButtonGridBagConstraints = new GridBagConstraints();
			editButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			editButtonGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			editButtonGridBagConstraints.insets = new Insets(0, 0, 5, 0);
			editButtonGridBagConstraints.gridx = 0;
			editButtonGridBagConstraints.gridy = 1;
			classpathControlPane.add(getEditButton(),
					editButtonGridBagConstraints);
			GridBagConstraints removeButtonGridBagConstraints = new GridBagConstraints();
			removeButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			removeButtonGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			removeButtonGridBagConstraints.insets = new Insets(0, 0, 5, 0);
			removeButtonGridBagConstraints.gridx = 0;
			removeButtonGridBagConstraints.gridy = 2;
			classpathControlPane.add(getRemoveButton(),
					removeButtonGridBagConstraints);
			GridBagConstraints listDriversButtonGridBagConstraints = new GridBagConstraints();
			listDriversButtonGridBagConstraints.insets = new Insets(0, 0, 5, 0);
			listDriversButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			listDriversButtonGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			listDriversButtonGridBagConstraints.gridx = 0;
			listDriversButtonGridBagConstraints.gridy = 3;
			classpathControlPane.add(getListDriversButton(),
					listDriversButtonGridBagConstraints);
			GridBagConstraints verticalGlueGridBagConstraints = new GridBagConstraints();
			verticalGlueGridBagConstraints.weighty = 10.0;
			verticalGlueGridBagConstraints.fill = GridBagConstraints.VERTICAL;
			verticalGlueGridBagConstraints.gridx = 0;
			verticalGlueGridBagConstraints.gridy = 4;
			classpathControlPane.add(getVerticalGlue(),
					verticalGlueGridBagConstraints);
		}
		return classpathControlPane;
	}

	private JButton getAddFileButton() {
		if (addFileButton == null) {
			addFileButton = new JButton("Add File");
			addFileButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					getOper().addDriverFileAction(e);
				}
			});
		}
		return addFileButton;
	}

	private JButton getEditButton() {
		if (editButton == null) {
			editButton = new JButton("Edit");
			editButton.setEnabled(false);
			editButton.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					getOper().editDriverFileAction(e);
				}
			});
		}
		return editButton;
	}

	private JButton getRemoveButton() {
		if (removeButton == null) {
			removeButton = new JButton("Remove");
			removeButton.setEnabled(false);
			removeButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					getOper().removeDriverFileAction(e);
				}
			});
		}
		return removeButton;
	}

	private JButton getListDriversButton() {
		if (listDriversButton == null) {
			listDriversButton = new JButton("List Drivers");
			listDriversButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					getOper().listDriverClassAction(e);
				}
			});
		}
		return listDriversButton;
	}

	private JLabel getClassLabel() {
		if (classLabel == null) {
			classLabel = new JLabel("Driver");
		}
		return classLabel;
	}

	JComboBox<String> getClassComboBox() {
		if (classComboBox == null) {
			classComboBox = new JComboBox<String>(this.getClassComboBoxModel());
		}
		return classComboBox;
	}

	private JPanel getTemplateMetaDataPane() {
		if (templateMetaDataPane == null) {
			templateMetaDataPane = new JPanel();
			templateMetaDataPane.setBorder(new TitledBorder(null, "Template",
					TitledBorder.LEADING, TitledBorder.TOP, null, null));
			GridBagLayout templateMetaDataPaneGridBagLayout = new GridBagLayout();
			templateMetaDataPane.setLayout(templateMetaDataPaneGridBagLayout);
			GridBagConstraints templateNameLabelGridBagConstraints = new GridBagConstraints();
			templateNameLabelGridBagConstraints.insets = new Insets(0, 0, 5, 5);
			templateNameLabelGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			templateNameLabelGridBagConstraints.gridx = 0;
			templateNameLabelGridBagConstraints.gridy = 0;
			templateMetaDataPane.add(getTemplateNameLabel(),
					templateNameLabelGridBagConstraints);
			GridBagConstraints templateNameComboBoxGridBagConstraints = new GridBagConstraints();
			templateNameComboBoxGridBagConstraints.weightx = 10.0;
			templateNameComboBoxGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			templateNameComboBoxGridBagConstraints.insets = new Insets(0, 0, 5,
					0);
			templateNameComboBoxGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			templateNameComboBoxGridBagConstraints.gridx = 1;
			templateNameComboBoxGridBagConstraints.gridy = 0;
			templateMetaDataPane.add(getTemplateNameComboBox(),
					templateNameComboBoxGridBagConstraints);
			GridBagConstraints templateLabelGridBagConstraints = new GridBagConstraints();
			templateLabelGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			templateLabelGridBagConstraints.insets = new Insets(0, 0, 5, 5);
			templateLabelGridBagConstraints.gridx = 0;
			templateLabelGridBagConstraints.gridy = 1;
			templateMetaDataPane.add(getTemplateLabel(),
					templateLabelGridBagConstraints);
			GridBagConstraints templateTextFieldGridBagConstraints = new GridBagConstraints();
			templateTextFieldGridBagConstraints.weightx = 10.0;
			templateTextFieldGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			templateTextFieldGridBagConstraints.insets = new Insets(0, 0, 5, 0);
			templateTextFieldGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			templateTextFieldGridBagConstraints.gridx = 1;
			templateTextFieldGridBagConstraints.gridy = 1;
			templateMetaDataPane.add(getTemplateTextField(),
					templateTextFieldGridBagConstraints);
			GridBagConstraints templateDriverLabelGridBagConstraints = new GridBagConstraints();
			templateDriverLabelGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			templateDriverLabelGridBagConstraints.insets = new Insets(0, 0, 5,
					5);
			templateDriverLabelGridBagConstraints.gridx = 0;
			templateDriverLabelGridBagConstraints.gridy = 2;
			templateMetaDataPane.add(getTemplateDriverLabel(),
					templateDriverLabelGridBagConstraints);
			GridBagConstraints templateDriverComboBoxGridBagConstraints = new GridBagConstraints();
			templateDriverComboBoxGridBagConstraints.insets = new Insets(0, 0,
					5, 0);
			templateDriverComboBoxGridBagConstraints.weightx = 10.0;
			templateDriverComboBoxGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			templateDriverComboBoxGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			templateDriverComboBoxGridBagConstraints.gridx = 1;
			templateDriverComboBoxGridBagConstraints.gridy = 2;
			templateMetaDataPane.add(getTemplateDriverComboBox(),
					templateDriverComboBoxGridBagConstraints);
			GridBagConstraints templateDescriptionLabelGridBagConstraints = new GridBagConstraints();
			templateDescriptionLabelGridBagConstraints.anchor = GridBagConstraints.BASELINE_TRAILING;
			templateDescriptionLabelGridBagConstraints.insets = new Insets(0,
					0, 0, 5);
			templateDescriptionLabelGridBagConstraints.gridx = 0;
			templateDescriptionLabelGridBagConstraints.gridy = 3;
			templateMetaDataPane.add(getTemplateDescriptionLabel(),
					templateDescriptionLabelGridBagConstraints);
			GridBagConstraints templateDescriptionTextFieldGridBagConstraints = new GridBagConstraints();
			templateDescriptionTextFieldGridBagConstraints.weightx = 10.0;
			templateDescriptionTextFieldGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			templateDescriptionTextFieldGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			templateDescriptionTextFieldGridBagConstraints.gridx = 1;
			templateDescriptionTextFieldGridBagConstraints.gridy = 3;
			templateMetaDataPane.add(getTemplateDescriptionTextField(),
					templateDescriptionTextFieldGridBagConstraints);
		}
		return templateMetaDataPane;
	}

	private JPanel getVariablePane() {
		if (variablePane == null) {
			variablePane = new JPanel();
			variablePane.setBorder(new TitledBorder(null, "Variable",
					TitledBorder.LEADING, TitledBorder.TOP, null, null));
			GridBagLayout variablePaneGridBagLayout = new GridBagLayout();
			variablePane.setLayout(variablePaneGridBagLayout);
			GridBagConstraints variableScrollPaneGridBagConstraints = new GridBagConstraints();
			variableScrollPaneGridBagConstraints.weighty = 10.0;
			variableScrollPaneGridBagConstraints.weightx = 10.0;
			variableScrollPaneGridBagConstraints.insets = new Insets(0, 0, 0, 5);
			variableScrollPaneGridBagConstraints.fill = GridBagConstraints.BOTH;
			variableScrollPaneGridBagConstraints.gridx = 0;
			variableScrollPaneGridBagConstraints.gridy = 0;
			variablePane.add(getVariableScrollPane(),
					variableScrollPaneGridBagConstraints);
			GridBagConstraints variableControlPaneGridBagConstraints = new GridBagConstraints();
			variableControlPaneGridBagConstraints.anchor = GridBagConstraints.PAGE_START;
			variableControlPaneGridBagConstraints.weighty = 10.0;
			variableControlPaneGridBagConstraints.fill = GridBagConstraints.VERTICAL;
			variableControlPaneGridBagConstraints.gridx = 1;
			variableControlPaneGridBagConstraints.gridy = 0;
			variablePane.add(getVariableControlPane(),
					variableControlPaneGridBagConstraints);
		}
		return variablePane;
	}

	private JLabel getTemplateNameLabel() {
		if (templateNameLabel == null) {
			templateNameLabel = new JLabel("Name");
		}
		return templateNameLabel;
	}

	private JComboBox getTemplateNameComboBox() {
		if (templateNameComboBox == null) {
			templateNameComboBox = new JComboBox();
		}
		return templateNameComboBox;
	}

	private JLabel getTemplateLabel() {
		if (templateLabel == null) {
			templateLabel = new JLabel("Template");
		}
		return templateLabel;
	}

	private JTextField getTemplateTextField() {
		if (templateTextField == null) {
			templateTextField = new JTextField();
			templateTextField.setColumns(10);
		}
		return templateTextField;
	}

	private JLabel getTemplateDriverLabel() {
		if (templateDriverLabel == null) {
			templateDriverLabel = new JLabel("Driver");
		}
		return templateDriverLabel;
	}

	private JComboBox getTemplateDriverComboBox() {
		if (templateDriverComboBox == null) {
			templateDriverComboBox = new JComboBox();
		}
		return templateDriverComboBox;
	}

	private JScrollPane getVariableScrollPane() {
		if (variableScrollPane == null) {
			variableScrollPane = new JScrollPane();
			variableScrollPane.setViewportView(getVariableTable());
		}
		return variableScrollPane;
	}

	private JPanel getVariableControlPane() {
		if (variableControlPane == null) {
			variableControlPane = new JPanel();
			GridBagLayout variableControlPaneGridBagLayout = new GridBagLayout();
			variableControlPane.setLayout(variableControlPaneGridBagLayout);
			GridBagConstraints addVariableButtonGridBagConstraints = new GridBagConstraints();
			addVariableButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			addVariableButtonGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			addVariableButtonGridBagConstraints.insets = new Insets(0, 0, 5, 0);
			addVariableButtonGridBagConstraints.gridx = 0;
			addVariableButtonGridBagConstraints.gridy = 0;
			variableControlPane.add(getAddVariableButton(),
					addVariableButtonGridBagConstraints);
			GridBagConstraints removeVariableButtonGridBagConstraints = new GridBagConstraints();
			removeVariableButtonGridBagConstraints.insets = new Insets(0, 0, 5,
					0);
			removeVariableButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			removeVariableButtonGridBagConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
			removeVariableButtonGridBagConstraints.gridx = 0;
			removeVariableButtonGridBagConstraints.gridy = 1;
			variableControlPane.add(getRemoveVariableButton(),
					removeVariableButtonGridBagConstraints);
			GridBagConstraints verticalGlue_1GridBagConstraints = new GridBagConstraints();
			verticalGlue_1GridBagConstraints.weighty = 10.0;
			verticalGlue_1GridBagConstraints.fill = GridBagConstraints.VERTICAL;
			verticalGlue_1GridBagConstraints.gridx = 0;
			verticalGlue_1GridBagConstraints.gridy = 2;
			variableControlPane.add(getVerticalGlue_1(),
					verticalGlue_1GridBagConstraints);
		}
		return variableControlPane;
	}

	private JButton getAddVariableButton() {
		if (addVariableButton == null) {
			addVariableButton = new JButton("Add");
		}
		return addVariableButton;
	}

	private JButton getRemoveVariableButton() {
		if (removeVariableButton == null) {
			removeVariableButton = new JButton("Remove");
		}
		return removeVariableButton;
	}

	private Component getVerticalGlue() {
		if (verticalGlue == null) {
			verticalGlue = Box.createVerticalGlue();
		}
		return verticalGlue;
	}

	private Component getVerticalGlue_1() {
		if (verticalGlue_1 == null) {
			verticalGlue_1 = Box.createVerticalGlue();
		}
		return verticalGlue_1;
	}

	private JTable getVariableTable() {
		if (variableTable == null) {
			variableTable = new JTable();
		}
		return variableTable;
	}

	private JLabel getTemplateDescriptionLabel() {
		if (templateDescriptionLabel == null) {
			templateDescriptionLabel = new JLabel("Description");
		}
		return templateDescriptionLabel;
	}

	private JTextField getTemplateDescriptionTextField() {
		if (templateDescriptionTextField == null) {
			templateDescriptionTextField = new JTextField();
			templateDescriptionTextField.setColumns(10);
		}
		return templateDescriptionTextField;
	}
}
